import { useReactive } from "ahooks";
import { useModel } from "umi";
import compress from "gql-compress";

const useUpdateSystemStaff = () => {
    const { graphqlFetch } = useModel("global");

    const state = useReactive({
        loading: false,
    });

    const updateSystemStaff = async (values, callback) => {
        state.loading = true;
        let variables = {
            osUuid: values.osUuid,
            osType: values.osType,
            opUuid: values.opUuid || null,
            deInfo: values.deInfo || {},
        };
        let res = await graphqlFetch({
            query,
            variables,
        });
        res && callback && callback(res);
        state.loading = false;
    };

    return { ...state, updateSystemStaff };
};

let query = compress(`mutation MyMutation(
    $osUuid: UUID!
    $osType: String!
    $opUuid: UUID
    $deInfo: JSON
  ) {
    updateOrganizationStaffByOsUuid(
        input: {
            osUuid: $osUuid
            organizationStaffPatch: {
                osType: $osType
                opUuid: $opUuid
                deInfo: $deInfo
            }
        }
    ) {
        clientMutationId
    }
}`);

export default useUpdateSystemStaff;
